<!DOCTYPE html>
<html>
<head>
    <meta charset="UTF-8">
    <title>活动预告</title>
    <meta name="viewport" content="width=device-width, initial-scale=1,maximum-scale=1, user-scalable=no">
    <meta name="apple-mobile-web-app-capable" content="yes">
    <meta name="apple-mobile-web-app-status-bar-style" content="black">
    <link href="../../plugins/mui/mui.min.css" rel="stylesheet" />
	<link href="../../css/style.css" rel="stylesheet"/>
	<script src="../../js/statistics.js"></script>
    <link rel="stylesheet" href="../../css/literary/activity_forecast.css">
</head>
<body>
<header class="mui-bar mui-bar-nav header">
    <a class="mui-action-back mui-icon mui-icon-left-nav mui-pull-left"></a>
    <h1 class="mui-title">活动预告</h1>
</header>
<div class="paging">
	<ul class="clear">
		<li class="active" newsId="0">
			全部
		</li>
	</ul>
</div>
<div id="refreshContainer" class="mui-content mui-scroll-wrapper">
	<div class="news_body mui-scroll">
		<ul>
			
		</ul>
	</div>
</div>
<div class='kong'>
	<img src="../../images/my/index/null.png" alt="" />
</div>
<script src="../../plugins/mui/mui.min.js"></script>
<script src="../../plugins/jquery/jquery-3.1.0.min.js"></script>
<script src="../../js/getApiToken.js"></script>
<script src="../../js/fontset.js"></script>
<script src="../../js/md5.js"></script>
<script src="../../plugins/template/template.js"></script>
<script id="type-list" type="text/html">
    {{each data as value i}}
	<li newsId="{{value.id}}">
		{{value.name}}
	</li>
	{{/each}}
</script>
<script id="news-list" type="text/html">
    {{each data as value i}}
   		<li class="clear" newsid="{{value.id}}" frontcover="'{{value.front_cover}}'">
			<div>
				<img src="{{baseUrl}}{{value.front_cover}}" /></img>
			</div>
			<div>
				<h4>{{value.title}}</h2>
				<p>活动时间：{{value.create_time}}</p>
			</div>
		</li>
   	{{/each}}
</script>
<script>
    var first = 0,
		id = 0,
		lastId;
	mui.init({
		pullRefresh : {
			container:"#refreshContainer",//下拉刷新容器标识，querySelector能定位的css选择器均可，比如：id、.class等
			up : {
				height:50,//可选.默认50.触发上拉加载拖动距离
				auto:false,//可选,默认false.自动上拉加载一次
				contentrefresh : "正在加载...",//可选，正在加载状态时，上拉加载控件上显示的标题内容
				contentnomore:'没有更多数据了',//可选，请求完毕若没有更多数据时显示的提醒内容；
				callback :function pullfresh() {
					if(true){
						console.log(id+'--'+lastId)
						myAjax('physical/News/getlist', 'post', {
							'type':id,
						 	'lastId':lastId,
						 	'total':6
						}, function(data) {
							if(data.code == 0){
								console.log(JSON.stringify(data))
								if(data.data.length == 0){
									mui('#refreshContainer').pullRefresh().endPullupToRefresh(true);
									
								}else{
									if(data.data.length < 6){
										mui('#refreshContainer').pullRefresh().endPullupToRefresh(true);
									}else{
										mui('#refreshContainer').pullRefresh().endPullupToRefresh(false);
									}
									loadMore(data.data);
									var length = data.data.length-1;
									lastId = data.data[length].id;
									console.log(lastId)
								}
							}else{
								mui.toast(data.error_msg);
							}
						})
					}
					first++;

				}
			}
		}
	});
	mui.plusReady(function(){
		id = plus.webview.currentWebview().type_id?plus.webview.currentWebview().type_id:0;
		myAjax('physical/activities/getType','get',{},function(data){
			if(data.code == 0){
				console.log(JSON.stringify(data.data))
				initType(data.data);
				//指定板块
				$(".paging").find("li").each(function(){
					var type = $(this).attr('newsId'),
						width = $(this).width();
		            if(id == type) {
		            	$(this).addClass('active');
		            	$(".paging ul").scrollLeft(width*type);
		            }else{
		            	$(this).removeClass('active');
		            }
				})
			}
				
		});
		
		
		myAjax('physical/notice/getlist','get',{'total':8,'type':id},function(data){
			console.log(JSON.stringify(data))
			if(data.code == 0){
				if(!data.data.length){
		 			$('.kong').show();
		 			$("#refreshContainer").hide();
					mui('#refreshContainer').pullRefresh().disablePullupToRefresh();
		 		}else{
		 			var length = data.data.length-1;
					lastId=data.data[length].id;
					initList(data.data);
		 		}
			}
		});
	})
	//类目初始化
	function initType(data){
		var list = {
			data:data
		};
		var html = template('type-list',list);
		$(".paging").find('ul').append(html);
	}
	//列表初始化
	function initList(data){
		var list = {
			data:data,
			baseUrl:_baseUrl
		};
		var html = template('news-list',list);
		$(".news_body").find('ul').empty().append(html);
	}
	//加载更多
	function loadMore(data){
		var list = {
			data:data,
			baseUrl:_baseUrl
		};
		var html = template('news-list',list);
		$(".news_body").find('ul').append(html);
	}
	//跳转详情
	function goNewDetail(id,img){
		mui.openWindow({
			url:'forecast_detail.html',
			id:'forecast_detail.html',
			extras:{
				detail_id:id,
				shareimg:img
			},
			waiting:{
	      		autoShow:true,//自动显示等待框，默认为true
	      		title:'正在加载...',//等待对话框上显示的提示内容
			},
			show:{
				autoShow:true,
				aniShow:'fade-in'
			}
		});
	}
	$(function(){
		//分页的切换
		$(".paging").delegate('li','tap',function(){
			id = $(this).attr('newsId');
			$(this).addClass('active').siblings().removeClass('active');
			mui('#refreshContainer').pullRefresh().refresh(true);
			myAjax('physical/notice/getlist','post',{
			 	'type':id,
			 	'lastId':0,
			 	'total':8
			},function(data){
			 	if(data.code == 0){
			 		if(!data.data.length){
			 			$('.kong').show();
			 			$("#refreshContainer").hide();
			 			$(".news_body").find('ul').empty()
						mui('#refreshContainer').pullRefresh().disablePullupToRefresh();
			 		}else{
			 			$('.kong').hide();
			 			$("#refreshContainer").show();
			 			var length = data.data.length-1;
						lastId=data.data[length].id;
						initList(data.data);
						mui('#refreshContainer').pullRefresh().enablePullupToRefresh();
			 		}
			 		
			 	}
			})
		})
		$(".news_body").delegate('li','tap',function(){
			var id = $(this).attr('newsid'),
				frontcover = $(this).attr('frontcover');
			goNewDetail(id,frontcover);
		})
	})	
</script>
</body>
</html>